<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <h1>今天的天气很{{info}}</h1>
        <button @click="changeWeather">点击切换天气</button>
        <hr>
        <h1>a的值是：{{numbers.a}}</h1>
        <button @click="numbers.a++">点我a++</button>
        <h1>b的值是：{{numbers.b}}</h1>
        <button @click="numbers.b++">点我b++</button>
    </div>
    <script>
        Vue.config.productionTip = false //取消生产提示

        const vm = new Vue({
            el: '#root',
            data() {
                return {
                    isHot: true,
                    numbers: {
                        a: 1,
                        b: 2
                    }
                }
            },
            computed: {
                info() {
                    return this.isHot ? '炎热' : '凉爽'
                }
            },
            methods: {
                changeWeather() {
                    this.isHot = !this.isHot
                }
            },
            watch: {
                isHot: {
                    //初始化时立刻调用
                    // immediate: true,
                    handler(newValue, oldValue) {
                        console.log('isHot被修改了', newValue, oldValue);
                    }
                },
                //监视多级结构中某个属性值的变化
                'numbers.a': {
                    handler() {
                        console.log('a被调用了');
                    }
                },
                //监视多级结构中所有属性值的变化
                numbers: {
                    deep: true,
                    handler() {
                        console.log('numbers变了');
                    }
                }
            },

        })
    </script>
</body>

</html>